/**
 * Created by zhangligang
 * Email: tzhang2450@163.com
 * Date: 2019/1/19
 * Time: 23:41
 */
$(function () {

    var id = $('.rule-id').val();

    sendAjax('/v1/manager/rule/detail.json', 'get', {id:id}, function (json) {
        $('.rule-realname').val(json.body.realname);
        $('.rule-username').text(json.body.username);
    });

    $('.btn-save').on('click', function(){
        var data = {
            id: $('.rule-id').val(),
            realname: $('.rule-realname').val(),
            password: $('.rule-password').val()
        };

        if (checkForm(data)) {
            saveData('/v1/manager/save/manager', {params:data}, '/manager/rule.html', '数据修改成功');
        }
    });
});

function checkForm(data) {
    if (data.realname == '') {
        alertTip('姓名不能为空');
        return false;
    }
    if (data.password == '') {
        alertTip('密码不能为空');
        return false;
    }
    return true;
}